# encoding: utf-8
import time
from apscheduler.events import EVENT_JOB_EXECUTED, EVENT_JOB_ERROR
from concurrent.futures import ThreadPoolExecutor
from app.modules.zones.resources import syncZoneAndApp

from app.modules.schedule import scheduler as sched
from app import app


# def scheduler_listener(event):
#     print repr(event)
#     print str(event)
#     if event.exception:
#         print('The job crashed :(')
#     else:
#         print('The job worked :)')
#
#
# sched.add_listener(scheduler_listener, EVENT_JOB_EXECUTED | EVENT_JOB_ERROR)


# 每30秒执行一次
# 从ucloud-master同步区域和应用信息
# 使用说明见http://apscheduler.readthedocs.io/en/latest/modules/triggers/interval.html?highlight=scheduled_job
@sched.scheduled_job(id = 'syncZoneAndAppSchedule', trigger = 'interval', executor = 'single', seconds = 60 * 30)
def syncZoneAndAppSchedule():
    with app.app_context():
        syncZoneAndApp()

# # 每2小时执行一次
# # 使用说明见http://apscheduler.readthedocs.io/en/latest/modules/triggers/interval.html?highlight=scheduled_job
# @sched.scheduled_job('interval', id='my_job2', hours=2)
# def my_job2():
#     print("Hello World")
#
#
# # 每天12点30分执行
# # 使用说明见http://apscheduler.readthedocs.io/en/latest/modules/triggers/cron.html?highlight=scheduled_job
# @sched.scheduled_job('cron', id='my_job3', hour=12, minute=30)
# def my_job3():
#     print("I am printed at 12:30:00 on every day!")
